﻿using Basic.FormGatewaryModular.Interface;
using Basic.FormRemoteModel.Page.Model;
using Basic.FormRemoteModel.PageBody.Model;
using WeDonekRpc.ApiGateway.Attr;
using WeDonekRpc.Client;
using WeDonekRpc.Helper.Validate;
using WeDonekRpc.HttpApiGateway;
using WeDonekRpc.HttpApiGateway.Model;

namespace Basic.FormGatewaryModular.Api
{
    [ApiRouteName("/form/page/{name}")]
    internal class CustomPageApi : ApiController
    {
        private readonly ICustomPageService _Service;

        public CustomPageApi ( ICustomPageService service )
        {
            this._Service = service;
        }
        public PageAppPower GetPower ( [NumValidate("form.page.id.error", 1)] long id )
        {
            return this._Service.GetPower(id);
        }
        public void AddPower ( LongParam<PageAppPower> obj )
        {
            this._Service.AddPower(obj.Id, obj.Value);
        }
        public void Enable ( [NumValidate("form.page.id.error", 1)] long id )
        {
            this._Service.Enable(id);
        }
        public void Disable ( [NumValidate("form.page.id.error", 1)] long id )
        {
            this._Service.Disable(id);
        }
        public PageControlDto GetLayout ( [NumValidate("form.page.layout.id.error", 1)] long layoutId, bool isEdit )
        {
            return this._Service.GetLayout(layoutId, isEdit);
        }
        public PageBodyDto GetBody ( [NumValidate("form.page.id.error", 1)] long id, bool isEdit )
        {
            return this._Service.GetBody(id, isEdit);
        }
        public long Add ( PageSet add )
        {
            PageAdd data = add.ConvertMap<PageSet, PageAdd>();
            data.CompanyId = base.UserState.ToCompanyId();
            return this._Service.Add(data);
        }

        public void Delete ( [NumValidate("form.page.id.error", 1)] long id )
        {
            this._Service.Delete(id);
        }

        public PageDatum Get ( [NumValidate("form.page.id.error", 1)] long id )
        {
            return this._Service.Get(id);
        }

        public PagingResult<PageDatum> Query ( PagingParam<PageQueryParam> query )
        {
            query.Query.CompanyId = base.UserState.ToCompanyId();
            return this._Service.Query(query);
        }

        public bool Set ( LongParam<PageSet> set )
        {
            return this._Service.Set(set.Id, set.Value);
        }
    }
}
